public class test01 {
    class Solution {
        List<List<Integer>> res;
        List<Integer> list;
        public List<List<Integer>> combine(int n, int k) {
            res = new ArrayList<>();
            list = new ArrayList<>();
            backTracking(n,k,1);
            return res;
        }
        private void backTracking(int n,int k,int begin){
            //记录begin是为了防止重复！
            if(list.size()==k){
                res.add(new ArrayList(list));
                //终止本层递归
                return;
            }
            for(int i = begin;i<=n-(k-list.size())+1;i++){
                list.add(i);
                backTracking(n,k,i+1);
                list.removeLast();
            }
        }
    }
}
